package com.ufo.collection;

import java.util.HashMap;
import java.util.Objects;

public class NoHashProblem {
    public static void main(String[] args){
        HashMap map=new HashMap();
        Person p=new Person("jo","123");
        map.put(p,"hahaha");
        Person p2=new Person("jo","123");
        assert map.get(p2)==null;
        System.out.println(map.get(p2));
    }
}
class Person{
    String name;
    String idCard;

    public Person(String name, String idCard) {
        this.name = name;
        this.idCard = idCard;
    }

//    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name) && Objects.equals(idCard, person.idCard);
    }

    //假设没有重写hash
//    @Override
//    public int hashCode() {
//        return Objects.hash(name, idCard);
//    }
}